﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Husb.Common;

namespace EasyUIDemo1.ViewModels
{
    internal class DictionaryViewModel
    {
        public static List<DictionaryItemViewModel> GetData()
        {
            List<DictionaryItem> items = DictionaryDataUtil.GetData();
            var q = (from i in items
                     select i.Category).Distinct();

            List<DictionaryItemViewModel> d = new List<DictionaryItemViewModel>();
            foreach (string i in q)
            {
                DictionaryItemViewModel m = new DictionaryItemViewModel();
                m.name = i;
                m.items = (from item in items
                           where item.Category == i
                           select new DictionaryDataItem
                           {
                               id = item.ID,
                               name = item.Name,
                               friendlyName = item.FriendlyName,
                               abbreviation = item.Abbreviation,
                               orderNumber = item.OrderNumber,
                               data = item.Data
                           }).ToList();
                d.Add(m);
            }

            return d;
        }

        public static List<ComboxViewModel> GetComboboxData()
        {
            List<DictionaryItem> items = DictionaryDataUtil.GetData();
            var q = (from i in items
                     select i.Category).Distinct();

            List<ComboxViewModel> d = new List<ComboxViewModel>();
            foreach (string i in q)
            {
                ComboxViewModel m = new ComboxViewModel();
                m.name = i;
                m.items = (from item in items
                           where item.Category == i
                           select new ComboxDataItem
                           {
                               id = item.ID,
                               text = item.Name
                           }).ToList();
                d.Add(m);
            }

            return d;
        }

        public static List<ComboxDataItem> GetData(string category)
        {
            
            List<DictionaryItem> items = DictionaryDataUtil.GetData();

            List<ComboxDataItem> data = (from item in items
                                         where item.Category == category
                                         select new ComboxDataItem
                                         {
                                             id = item.ID,
                                             text = item.Name
                                         }).ToList();
            return data;
        }
    }

    internal class DictionaryItemViewModel
    {
        public string name { get; set; }

        public List<DictionaryDataItem> items { get; set; }
    }

    internal class ComboxViewModel
    {
        public string name { get; set; }

        public List<ComboxDataItem> items { get; set; }
    }

    internal class DictionaryDataItem
    {
        /// <summary>
        /// 项的唯一识别号
        /// </summary>
        public int id { get; set; }
        /// <summary>
        /// 条目英文名称
        /// </summary>
        public string name { get; set; }
        /// <summary>
        /// 项友好名称
        /// </summary>
        public string friendlyName { get; set; }
        /// <summary>
        /// 缩写
        /// </summary>
        public string abbreviation { get; set; }
        /// <summary>
        /// 排序号
        /// </summary>
        public int orderNumber { get; set; }
       
        /// <summary>
        /// 项数据
        /// </summary>
        public string data { get; set; }
    }

    internal class ComboxDataItem
    {
        /// <summary>
        /// 项的唯一识别号
        /// </summary>
        public int id { get; set; }
        /// <summary>
        /// 条目英文名称
        /// </summary>
        public string text { get; set; }
        
    }


}